package com.blacktea.structuralpatterns.facadepattern.controller;

import com.blacktea.structuralpatterns.facadepattern.entity.App01Userinfo;
import com.blacktea.structuralpatterns.facadepattern.service.App01UserInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

/**
 * @description:
 * @author: black tea
 * @date: 2023/3/22 23:00
 */
@RequestMapping("/user/")
@RestController
@RequiredArgsConstructor
public class UserInfoController {

    private final App01UserInfoService userInfoService;

    @GetMapping("{name}")
    public App01Userinfo getByUserInfo(@PathVariable String name){
        Optional<App01Userinfo> userInfoOpt = userInfoService.getUserByName(name);
        return userInfoOpt.orElseGet(App01Userinfo::new);
    }

}
